
-- 模块定义
local M = 
{
	_base_class = require "objects.Object",
	_class_name = "tools.IdGenerator"
}
setmetatable (M, {__index = _G;});
_ENV = M;

-- 引用模块
local Tools = require ("tools.CommonTools");

-- 方法定义
operation_table = Tools.CreateOperationTable (_base_class);

-- 获得下一个id
function operation_table.GetNextId (self)
	local result_id = self._current_id;

	self._current_id = self._current_id + 1;
	if (self._current_id > self._end_id) then
		self._current_id = self._start_id;
	end

	return result_id;
end

-- 构造方法
-- @start_id 起始id
-- @end_id 节止id，生成的id超过该值时，将从start_id重新分配
function NewIdGenerator (start_id, end_id)
	local instance = _base_class.NewObject ();
	Tools.PrepareInstance (M, instance);
	
	-- 在这里定义成员变量
	instance._start_id = start_id;
	instance._end_id = end_id;
	instance._current_id = start_id;
	
	return instance;
end;

return M;